package org.example.entity;

import org.example.util.DateUtil;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;

/**
 * @author TonySong
 * 学生票：继承普通票：折扣
 * @date 2025/7/28 0028
 * @time 16:32
 */
public class StudentTicket extends Ticket implements Serializable {
    private Integer discount;//折扣

    @Override
    public int calc() {
        //    100 * 8 /10
        return this.getMovie().getPrice() * this.discount / 10;
    }

    public Integer getDiscount() {
        return discount;
    }

    public void setDiscount(Integer discount) {
        this.discount = discount;
    }



    public StudentTicket(Movie movie) {
        super(movie);

    }

    @Override
    public String toString() {
        return super.toString()+"StudentTicket{" +
                "discount=" + discount +
                '}';
    }

    @Override
    public void print() throws IOException {
        String fname= DateUtil.createTime();
        PrintWriter writer =new PrintWriter(new FileWriter("学生票"+fname+".txt"));
        writer.println("========================夜不归宿电影院欢迎您====================================\r\n");
        writer.println("电影名称："+this.getMovie().getName()+"时间："+DateUtil.showDate(this.getMovie().getPlayTime())+"\r\n");
        writer.print("座位号："+this.getSeat()+"\r\n");
        writer.print("票价："+this.calc()+"元\r\n");
        writer.print("学生票，折扣:"+this.discount+"\r\n");
        writer.print("====================感谢您的光临====================\r\n");
        writer.close();
    }
}
